package net.cl.mvc.pagination;

public class PageListImpl extends Pagination {

	/**
	 * 返回如下格式的分页<br>
	 * 共1085条记录 第1/109页 首页 上一页 | 下一页 末页
	 * 
	 * @param url
	 *            request.getRequestURI()
	 */
	@Override
	public String toPageCode(String url) {
		StringBuilder sb = new StringBuilder();
		sb.append("共").append(getNumberOfPages()).append("条记录&nbsp;");
		sb.append("第").append(getCurrentPage()).append("/").append(getNumberOfPages()).append("页&nbsp;");
		if (hasPrevious()) {
			sb.append("<a href=\"").append(url).append("?page=1\">首页</a> ");
			sb.append("<a href=\"").append(url).append("?page=").append(getPreviousPage()).append("\">上一页</a>");
		} else {
			sb.append("首页&nbsp;上一页");
		}
		sb.append("&nbsp;|&nbsp;");
		if (hasNext()) {
			sb.append("<a href=\"").append(url).append("?page=").append(getNextPage()).append("\">下一页</a> ");
			sb.append("<a href=\"").append(url).append("?page=").append(getNumberOfPages()).append("\">末页</a>");
		} else {
			sb.append("下一页&nbsp;末页");
		}
		return sb.toString();
	}

}
